package com.aos.erp.schools.service.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public Queue toGovNewStudent() {
        return new Queue(QueueConstants.toGovNewStudent);
    }

    /**
     * 交换机
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(QueueConstants.gov_direct_exchange);
    }


    /**
     * 驾校提交queue
     *
     * @return
     */
    @Bean
    public Queue toSchoolStudentSubmitted() {
        return new Queue(QueueConstants.toSchoolStudentSubmitted);
    }

    /**
     * 驾校提交queue和routingkey绑定
     *
     * @return
     */
    @Bean
    public Binding bindingDirectExchangeSchoolSubmitted(Queue toSchoolStudentSubmitted, DirectExchange directExchange) {
        return BindingBuilder.bind(toSchoolStudentSubmitted).to(directExchange).with(QueueConstants.gov_direct_exchange_key_submitted);
    }


    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter() {
        Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
        return converter;
    }


}
